summaryrefslogtreecommitdiff
path: root/src/pages/pengajuan-tempo/[status].jsx
blob: c97b589745fafd7d1cfbf993c7fcae2e9964b678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import BasicLayout from '@/core/components/layouts/BasicLayout';
import IsAuth from '@/lib/auth/components/IsAuth';
import FinishTempoComponent from '@/lib/pengajuan-tempo/component/FinishTempo';
import { useRouter } from 'next/router';
import axios from 'axios';
import { useState, useEffect } from 'react';
import Seo from '@/core/components/Seo';
import { getAuth } from '~/libs/auth';

export async function getServerSideProps(context) {
  const { tempo_id } = context.query;
  // await axios.post(
  //   `${process.env.NEXT_PUBLIC_SELF_HOST}/api/pengajuan-tempo?formId=${tempo_id}`,
  //   {},
  //   { headers: context.req.headers }
  // );
  return { props: {} };
}

export default function Finish() {
  const [isLoading, setIsLoading] = useState(true);
  const router = useRouter();
  const auth = getAuth();
  useEffect(() => {
    if (!auth) {
      const nextUrl = encodeURIComponent(router.asPath);
      router.push(`/login?next=${nextUrl}`);
    } else if (
      (router.query.status == 'approve' || router.query.status == 'review') &&
      auth.tempoProgres === ''
    ) {
      router.push('/pengajuan-tempo');
    } else {
      setIsLoading(false);
    }
  }, [auth]);

  if (isLoading || !auth) {
    return null; // Tidak render apa pun selama loading atau auth/tempo belum tersedia
  }
  return (
    <>
      <Seo title='Pengajuan Tempo Indoteknik.com' />

      <IsAuth>
        <BasicLayout>
          <FinishTempoComponent query={router.query || {}} />
        </BasicLayout>
      </IsAuth>
    </>
  );
}